package com.usf.jprovider.schema.provider.random.date;

import java.text.ParseException;
import java.util.Date;

import javax.xml.bind.annotation.XmlAttribute;

import com.usf.jprovider.object.JObjectNode;
import com.usf.jprovider.object.env.Environment;
import com.usf.jprovider.object.type.JDate;
import com.usf.jprovider.object.type.JType;
import com.usf.jprovider.tools.DateTools;
import com.usf.jprovider.tools.RandomTools;

public final class DateRandom extends AbstractDateRandomProvider {

	@XmlAttribute protected String min;
	@XmlAttribute protected String max;

	public DateRandom() {
		super();
		min = "";
		max = "";
	}
	public String getMin() {
		return min;
	}
	public String getMax() {
		return max;
	}

	@Override
	public JDate create(Environment env, JObjectNode node) throws ParseException {
		Date dmin = DateTools.valueOf(min, type.getFormat());
		Date dmax = DateTools.valueOf(max, type.getFormat());
		return new JDate(RandomTools.randomizeDate(dmin, dmax), type.getFormat());
	}

	@Override
	public boolean checkValue(Environment env, JObjectNode node, JType<?> value) throws Exception {
		return true;//TODO
	}

}
